package com.itheima.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.itheima.mapper.ReportMapper;
import com.itheima.service.ReportService;
import com.itheima.vo.EmpJobDataVo;
import com.itheima.vo.ReporetVo;
import com.itheima.vo.clazzCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;

    @Override
    public List<ReporetVo> genderdata() {
        return reportMapper.count();
    }

    @Override
    public EmpJobDataVo empjobdata() {
        /*EmpJobDataVo jobdata = reportMapper.jobdata();
        return jobdata;*/
        List<ReporetVo> list = reportMapper.jobdata();
        //使用stream流实现
        //遍历 List<ItemVo>， 将每个ItemVo的职位名称获取出来，形成一个新的List<String>
        List<String> jobs = list.stream().map(vo -> vo.getName()).collect(Collectors.toList());
        //遍历 List<ItemVo>， 将每个ItemVo的职位数量获取出来，形成一个新的List<Integer>
        List<Integer> counts = list.stream().map(vo -> vo.getValue()).collect(Collectors.toList());

        List<String> name = CollUtil.getFieldValues(list, "name", String.class);
        List<Integer> value = CollUtil.getFieldValues(list, "value", Integer.class);

        return EmpJobDataVo.builder().jobList(jobs).dataList(counts).build();
    }

    @Override
    public List<Map> studentdegree() {
        List<Map> studentdegree = reportMapper.studentdegree();
        return studentdegree;
    }

    @Override
    public clazzCountVo getStudentCountData() {
        List<Map> countList = reportMapper.getStudentCount();
        List<Object> clazzList = countList.stream().map(map -> map.get("cname")).collect(Collectors.toList());
        List<Object> dataList = countList.stream().map(map -> map.get("scount")).collect(Collectors.toList());
        return new clazzCountVo(clazzList, dataList);
    }
}
